// pages/init/init.js
const app = getApp()
const api = app.globalData.api
Page({
    /**
     * 页面的初始数据
     */
    data: {
        corpname: '',
        backgroundUrl: app.controlDomain + 'img/control/init_back.jpg'
    },
    onChange(event) {
        // event.detail 为当前输入的值
        this.setData({
            corpname: event.detail
        })
    },
    /**提交数据 */
    async commit() {
        const uid = wx.getStorageSync('uid'),
            corpid = wx.getStorageSync('corpid')
        if (!uid) {
            api.showToast('系统错误')
        } else {
            const res = await api.curlPost('wechatInitClass.php?fun=setUser', {
                corpname: this.data.corpname,
                uid: uid,
                corpid: corpid
            }, app.controlRoot)
            if (res.code !== 1) {
                api.showToast(res.warn)
            } else {
                const root = res.data.url.replace('?', '')
                wx.removeStorageSync()
                wx.reLaunch({
                    url: '/pages/index/index',
                    complete() {
                        wx.setStorageSync('realUrl', root)
                        app.root = root
                        app.isReal = true
                        api.login()
                    }
                })
            }
        }
    },
})
